class_name Interactable
extends Area2D

#region 属性
@export var interact_key:Key
@export var show_interactive_btn:bool = true
@export var stay_time:float = 0.5
@export var offest:Vector2
@export var interactive_btn: InteractiveBtn
@export var sprite2d:Sprite2D
@export var is_auto_interact:bool = false
@export var additional_effects:Array[AdditionalEffect]
#endregion
#region 字段
#endregion
#region 信号
signal iteract_completed(interactor:Interactor)
#endregion

#region 基类方法
#endregion
#region 公共方法
func init_interactable_item():
	interactive_btn.init_interactive_btn(interact_key,stay_time)
	interactive_btn.visible = false
	interactive_btn.interact_completed.connect(on_interact_completed)
func set_seleted(selectd:bool):
	sprite2d.material.set_shader_parameter("enable",selectd)
	interactive_btn.visible = show_interactive_btn and selectd
	visible = selectd
func set_enable(enable:bool):
	visible = enable
	monitoring = enable
	monitorable = enable
	for child in  get_children():
		if child is CollisionShape2D:
			child.disabled = not enable
func start_interact(interactor:Interactor):
	interactive_btn.start_interact(interactor)
func end_interact(interactor:Interactor):
	interactive_btn.end_interact(interactor)
func interacting():
	pass
func on_interact_completed(interactor:Interactor):
	for additional_effect:AdditionalEffect in additional_effects:
		additional_effect = additional_effect.duplicate(true)
		additional_effect.init({Target = interactor.entity,Owner = self})
		additional_effect.excute()
	iteract_completed.emit(interactor)
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _ready() -> void:
	interactive_btn.position += offest
	init_interactable_item()
#endregion
